#------------------------------------------------------------------
# Project Senior Project
# name Game.py
#------------------------------------------------------------------
# Project Senior Project
# name Game.py
# purpose Game run file
#
# authors Chris L'Heureux
# 
# created 1/14/14
# Copyright (C) Chris L'Heureux
# License New BSD\
#
#https://code.google.com/p/seniorprojectgame/
#------------------------------------------------------------------  
import pygame, sys, math, random

from Block import Block

class Enemy(Block):
    def __init__(self, image, pos = (0,0), blocksize = [50,50]):
        Block.__init__(self, image, pos, blocksize)
        self.maxSpeed = blocksize[0]/14.0
        self.living = True
        self.detectRange = 100
        self.seePlayer = False
        self.headingx = "right"
        self.headingy = "up"
        self.directionCount = 0
        self.realx = pos[0]
        self.realy = pos[1]
        self.x = pos[0]
        self.y = pos[1]
        self.offsetx = 0
        self.offsety = 0
         
    def place(self, position):
        self.rect.center = position
        
    def die(self):
        self.living = False
    
    def move (self):
        self.rect.center = [int(self.x), int(self.y)]
    
    def collideWall(self, screenWidth, screenHeight):
        if (self.rect.left < 0 or self.rect.right > screenWidth):
                self.living = False 
        if (self.rect.top < 0 or self.rect.top > screenHeight):
                self.living = False
            
            
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))            

    
    def collideEnemy(self, other):
         if (self.rect.right > other.rect.left 
             and self.rect.left < other.rect.right):
             if (self.rect.bottom > other.rect.top and 
                 self.rect.top < other.rect.bottom):
                 if (self.distToPoint(other.rect.center)
                     < self.radius + other.radius):                 
                     other.die() and self.die()

                     
    def collidePlayer(self, other):
         if (self.rect.right > other.rect.left 
             and self.rect.left < other.rect.right):
             if (self.rect.bottom > other.rect.top and 
                 self.rect.top < other.rect.bottom):
                 if (self.distToPoint(other.rect.center)
                     < self.radius + other.radius):                 
                        other.die() and self.die()

                        
    
    
        
        
                     